package dexter.net.unit;

import dexter.core.host.HostAddress;
import dexter.net.msg.BusMessage;
import dexter.net.node.AbstractNode;

public class DummyNode extends AbstractNode {
	
	private static int globalCount = 0;
	
	public DummyNode(String context, HostAddress address) {
		super(context, address, null);
	}

	public void messageArrive(BusMessage msg) {
		
		if (msg instanceof DummyMessage) {
			HostAddress source = msg.getFromAddress();	
			System.out.println("DummyNode "+getHostAddress()+" : hello from "+source);
			incCount();
		}	
		else {
			System.out.println("DummyNode : error message "+msg);
		}
		
	}
	
	public void sayHello(HostAddress host, int num) {
		super.send(host, new DummyMessage(getHostAddress()));
		System.out.println("DummyNode "+getHostAddress()+" : say hello num "+num+"to "+host);
	}
	
	public static void reset() {
		globalCount = 0;
	}
	
	public static void incCount() {
	   globalCount++;	
	}
	
	public static int getCount() {
		return globalCount;
	}

}
